// coding: utf-8
// @Author : lryself
// @Date : 2020/10/26 23:12
// @Software: GoLand

package main

func main() {
	
}
func sortString(s string) string {
	var newlist [26]int
	result := ""
	for _,i := range s{
		newlist[i-'a']++
	}
	chlist := [][]int{}
	for index,i := range newlist{
		if i > 0{
			chlist = append(chlist, []int{index, i})
		}
	}
	for len(result) < len(s){
		for i:=0;i< len(chlist);i++{
			if chlist[i][1] > 0{
				result += string(rune(chlist[i][0] + 'a'))
				chlist[i][1]--
			}
		}
		for i:=len(chlist)-1;i>=0;i--{
			if chlist[i][1] > 0{
				result+=string(rune(chlist[i][0]+'a'))
				chlist[i][1]--
			}
		}
	}
	return result
}